<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  <link rel="stylesheet" href="docgen-resources/docgen.css" type="text/css">
  <meta name="generator" content="FreeMarker Docgen (DocBook 5)">
  <title>
    FreeMarker Manual - Node variables
  </title>
    <script type="text/javascript" src="docgen-resources/jquery.js"></script>
    <script type="text/javascript" src="docgen-resources/linktargetmarker.js"></script>
</head>
<body>

    <div class="navigation">
    <div class="breadcrumb">
<span class="breadcrumb">        You are here:
          <a href="index.html">Book</a>
            <b>></b>
          <a href="pgui.html">Programmer's Guide</a>
            <b>></b>
          <a href="pgui_datamodel.html">The Data Model</a>
            <b>></b>
          Node variables
</span>    </div>
    <div class="bookmarks">
<span class="bookmarks">Bookmarks:
<a href="alphaidx.html">Alphabetical Index</a>, <a href="gloss.html">Glossary</a>, <a href="ref.html">Reference</a>, <a href="app_faq.html">FAQ</a>, <a href="api/index.html">Java API</a>, <a href="../index.html">FreeMarker Home</a></span>    </div>
    <div class="pagers">
      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
<div class="pagerButton"><a href="pgui_datamodel_objectWrapper.html"><span class="hideA">Next page: </span>Object wrappers</a></div><div class="pagerButton"><a href="pgui_datamodel_directive.html">Previous page</a></div><div class="pagerButton"><a href="pgui_datamodel.html">Parent page</a></div><div class="pagerButton"><a href="index.html">Contents</a></div>      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
    </div>
    </div>

<div id="mainContent">

  
  
  
  
  <h1 class="rank_section1"
        id="pageTopTitle">
<a name="pgui_datamodel_node"></a>Node variables  </h1>
    
    
<p>A node variable embodies a node in a tree structure. Node
        variables were introduced to help <a href="xgui.html">the handling of
        XML documents in the data-model</a>, but they can be used for the
        modeling of other tree structures as well. For more information about
        nodes from the point of view of the template language <a href="dgui_datamodel_types.html#dgui_datamodel_node">read this earlier section</a>.</p><p>A node variable has the following properties, provided by the
        methods of <tt style="color: #A03D10">TemplateNodeModel</tt> interface:</p>    <div class="itemizedlist">
<ul>
          <li>
            <p>Basic properties:</p>

                <div class="itemizedlist">
<ul>
              <li>
                <p><tt style="color: #A03D10">TemplateSequenceModel
                getChildNodes()</tt>: A node has sequence of children
                (except if the node is a leaf node, in which case the method
                return an empty sequence or null). The child nodes should be
                node variables as well.</p>
              </li>

              <li>
                <p><tt style="color: #A03D10">TemplateNodeModel getParentNode()</tt>: A
                node has exactly 1 parent node, except if the node is root
                node of the tree, in which case the method returns
                <tt style="color: #A03D10">null</tt>.</p>
              </li>
            </ul>    </div>

          </li>

          <li>
            <p>Optional properties. If a property does not make sense in
            the concrete use case, the corresponding method should return
            <tt style="color: #A03D10">null</tt>:</p>

                <div class="itemizedlist">
<ul>
              <li>
                <p><tt style="color: #A03D10">String getNodeName()</tt>: The node name
                is the name of the macro, that handles the node when you use
                <a href="ref_directive_visit.html#ref.directive.recurse"><tt>recurse</tt></a>
                and <a href="ref_directive_visit.html#ref.directive.visit"><tt>visit</tt></a>
                directives. Thus, if you want to use these directives with the
                node, the node name is <i>required</i>.</p>
              </li>

              <li>
                <p><tt style="color: #A03D10">String getNodeType()</tt>: In the case of
                XML: <tt style="color: #A03D10">&quot;element&quot;</tt>, <tt style="color: #A03D10">&quot;text&quot;</tt>,
                <tt style="color: #A03D10">&quot;comment&quot;</tt>, ...etc. This information, if
                available, is used by the <tt style="color: #A03D10">recurse</tt> and
                <tt style="color: #A03D10">visit</tt> directives to find the default
                handler macro for a node. Also it can be useful for other
                application specific purposes.</p>
              </li>

              <li>
                <p><tt style="color: #A03D10">String getNamespaceURI()</tt>: The node
                namespace (has nothing to do with FTL namespaces used for
                libraries) this node belongs to. For example, in the case of
                XML, this is the URI of the XML namespace the element or
                attribute belongs to. This information, if available, is used
                by the <tt style="color: #A03D10">recurse</tt> and <tt style="color: #A03D10">visit</tt>
                directives to find the FTL namespaces that store the handler
                macros.</p>
              </li>
            </ul>    </div>

          </li>
        </ul>    </div>
<p>On the FTL side, the direct utilization of node properties is
        done with <a href="ref_builtins_node.html">node built-ins</a>, and
        with the <tt style="color: #A03D10">visit</tt> and <tt style="color: #A03D10">recurse</tt>
        macros.</p><p>In most use cases, variables that implement
        <tt style="color: #A03D10">TemplateNodeModel</tt>, implement other interfaces as
        well, since node variable properties just provide the basic
        infrastructure for navigating between nodes. For a concrete example,
        see <a href="xgui.html">how FreeMarker deals with XML</a>.</p>  
</div>

    <div class="navigation">
    <div class="pagers">
      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
<div class="pagerButton"><a href="pgui_datamodel_objectWrapper.html"><span class="hideA">Next page: </span>Object wrappers</a></div><div class="pagerButton"><a href="pgui_datamodel_directive.html">Previous page</a></div><div class="pagerButton"><a href="pgui_datamodel.html">Parent page</a></div><div class="pagerButton"><a href="index.html">Contents</a></div>      <div class="pagersVerticalSpacer"><img src="docgen-resources/img/none.gif" width="1" height="1" alt="" hspace="0" vspace="0" border="0"/></div>
    </div>
    <div class="breadcrumb">
<span class="breadcrumb">        You are here:
          <a href="index.html">Book</a>
            <b>></b>
          <a href="pgui.html">Programmer's Guide</a>
            <b>></b>
          <a href="pgui_datamodel.html">The Data Model</a>
            <b>></b>
          Node variables
</span>    </div>
    </div>

<table border=0 cellspacing=0 cellpadding=0 width="100%">
    <tr>
      <td colspan=2><img src="docgen-resources/img/none.gif" width=1 height=8 alt=""></td>
    <tr>
      <td align="left" valign="top"><span class="smallFooter">
            FreeMarker Manual -- For FreeMarker 2.3.16
            <br>
          HTML generated: 2009-12-08 08:38:54 GMT
      </span></td>
      <td align="right" valign="top"><span class="smallFooter">
          <a href="http://www.xmlmind.com/xmleditor/">
            <img src="docgen-resources/img/xxe.gif" alt="Edited with XMLMind XML Editor">
          </a>
      </span></td>
    </tr>
</table>
  <!-- Put pre-loaded images here: -->
  <div style="display: none">
    <img src="docgen-resources/img/linktargetmarker.gif" alt="Here!" />
  </div>
</body>
</html>

